Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
open-in-editor
Advanced tools
NPM package to open a file in editor.
Supported editors:
You also can use any other editor that is able to open files from command line.
npm install open-in-editor
First of all you should create an interface with your settings.
var openInEditor = require('open-in-editor');
var editor = openInEditor.configure({
// options
}, function(err) {
console.error('Something went wrong: ' + err);
});
Resulting object has a single method open
. This method runs terminal command that opens an editor. Result of this method is a promise:
editor.open('path/to/file.js:3:10')
.then(function() {
console.log('Success!');
}, function(err) {
console.error('Something went wrong: ' + err);
});
openInEditor.configure([options][, failCallback]);
Arguments:
options
– optional is used to set up a command to launch an editor. If no options set it will try to get the command from environmentfailCallback
– optional function that is called when something's wrong with editor setup.If editor setup was successful configure
method returns an interface with single method open
. The method accepts file reference with the following format: filename[:line[:column]]
, where line
and column
tell the editor where to place cursor when file is opened.
Type: String
or null
Values: 'sublime'
, 'atom'
, 'code'
, 'webstorm'
, 'phpstorm'
, 'idea14ce'
, 'vim'
, 'emacs'
, 'visualstudio'
Default: null
Editor to open a file. Once value is set, we try to detect a command to launch an editor.
Supported editors:
sublime
– Sublime Textatom
– Atom Editorcode
– Visual Studio Codewebstorm
– WebStormphpstorm
- PhpStormidea14ce
– IDEA 14 CEvim
– Vim (via Terminal, Mac OS only)emacs
– Emacs (via Terminal, Mac OS only)visualstudio
– Visual StudioType: String
or null
Default: null
Command to launch an editor.
var openInEditor = require('open-in-editor');
var editor = openInEditor.configure({
cmd: '/path/to/editor/app'
});
If editor
option is also set, an editor settings are using as default settings.
var openInEditor = require('open-in-editor');
var editor = openInEditor.configure({
editor: 'code',
cmd: '/path/to/editor/app' // will be called as '/path/to/editor/app -r -g {filename}:{line}:{column}'
});
Type: String
or null
Default: null
Option to specify arguments for a command. Pattern can contain placeholders to be replaced by actual values. Supported placeholders: filename
, line
and column
.
var openInEditor = require('open-in-editor');
var editor = openInEditor.configure({
cmd: 'code',
pattern: '-r -g {filename}:{line}:{column}'
});
If there's no {filename}
placeholder in the command then {filename}:{line}:{column}
is appended. That way previous example can be simplified:
var openInEditor = require('open-in-editor');
var editor = openInEditor.configure({
cmd: 'code',
pattern: '-r -g' // the same as '-r -g {filename}:{line}:{column}'
});
Type: Number
Default: 1
Defines the number of the first line in the editor. Usually it's 1
, but you can set it to 0
.
Type: Number
Default: 1
Defines the number of the first column in the editor. Usually it's 1
, but you can set it to 0
.
If no editor
or cmd
option is specified, we try to get the command to launch an editor using environment settings. Following values can be used (in descending priority):
process.env.OPEN_FILE
process.env.VISUAL
process.env.EDITOR
First value found is used. If it's process.env.VISUAL
or process.env.EDITOR
, it's used directly as cmd
option. But process.env.OPEN_FILE
is different: if value is a valid for editor
option, it's used for it, otherwise it's used as a value for cmd
option.
You can set env settings per command:
OPEN_FILE=atom oe path/to/file.js:4:15
OPEN_FILE="code -r -g" node script.js
Package could be installed globally.
npm install open-in-editor -g
In this case oe
command will be available in terminal.
Usage:
oe [filename] [options]
Options:
--cmd <command> Command to open file
--debug Debug errors
-e, --editor <editor> Editor: atom, code, sublime, webstorm, phpstorm, idea14ce, vim, visualstudio, emacs
-f, --file <filename> File to open
-h, --help Output usage information
-p, --pattern <pattern> Filename pattern and args, i.e. something going after cmd
-v, --version Output the version
Express
extension to open files from browser.Babel
plugin that instruments source code to associate objects with location they defined in code base.React
, Backbone
and can be adopted for other frameworks.MIT
2.2.0 (March 22, 2017)
open()
when only cmd
option is set (#10)editor
and cmd
options are specified--pattern
option to CLIFAQs
Open file in editor
The npm package open-in-editor receives a total of 10,562 weekly downloads. As such, open-in-editor popularity was classified as popular.
We found that open-in-editor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.